// SPDX-License-Identifier: GPL-2.0-or-later

#include <Snake/Snake.hpp>

#include <Snake/Position.hpp>
#include <Snake/Direction.hpp>

Snake::Snake() : body({{0, 1}, {0, 0}}), direction(Direction::Down)
{
}

Position Snake::getNextPosition() const
{
	Position head = this->body.front();

	switch(this->direction)
	{
		case Direction::Left:
			return {head.x - 1, head.y};

		case Direction::Right:
			return {head.x + 1, head.y};

		case Direction::Top:
			return {head.x, head.y - 1};

		case Direction::Down:
			return {head.x, head.y + 1};
	}
}

void Snake::move()
{
	this->body.pop_back();
	this->body.push_front(this->getNextPosition());
}

void Snake::grow()
{
	this->body.push_front(this->getNextPosition());
}
